package com.efast.dmom.mgmt.service.master.impl;
import java.util.Date;
import java.util.List;

import com.efast.cafe.framework.bean.ResultBean;
import com.efast.cafe.framework.util.SpringWebUtils;
import com.efast.dmom.mgmt.dao.master.TrBasRouteOperationDao;
import com.efast.dmom.mgmt.entity.master.TmBasRoute;
import com.efast.dmom.mgmt.entity.master.TrBasRouteOperation;
import com.efast.dmom.mgmt.service.master.TmBasRouteService;
import com.efast.dmom.mgmt.service.master.TrBasRouteOperationService;
import com.efast.dmom.mgmt.utils.Assist;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class TrBasRouteOperationServiceImpl implements TrBasRouteOperationService{
    @Autowired
    private TrBasRouteOperationDao trBasRouteOperationDao;
	@Autowired
	private TmBasRouteService tmBasRouteService;
    @Override
    public long getTrBasRouteOperationRowCount(Assist assist){
        return trBasRouteOperationDao.getTrBasRouteOperationRowCount(assist);
    }
    @Override
    public List<TrBasRouteOperation> selectTrBasRouteOperation(Assist assist){
        return trBasRouteOperationDao.selectTrBasRouteOperation(assist);
    }
    @Override
    public TrBasRouteOperation selectTrBasRouteOperationByObj(TrBasRouteOperation obj){
        return trBasRouteOperationDao.selectTrBasRouteOperationByObj(obj);
    }
    @Override
    public TrBasRouteOperation selectTrBasRouteOperationById(Integer id){
        return trBasRouteOperationDao.selectTrBasRouteOperationById(id);
    }
    @Override
    public int insertTrBasRouteOperation(TrBasRouteOperation value){
        return trBasRouteOperationDao.insertTrBasRouteOperation(value);
    }
    @Override
    public int insertNonEmptyTrBasRouteOperation(TrBasRouteOperation value){
        return trBasRouteOperationDao.insertNonEmptyTrBasRouteOperation(value);
    }
    @Override
    public int insertTrBasRouteOperationByBatch(List<TrBasRouteOperation> value){
        return trBasRouteOperationDao.insertTrBasRouteOperationByBatch(value);
    }
    @Override
    public int deleteTrBasRouteOperationById(Integer id){
        return trBasRouteOperationDao.deleteTrBasRouteOperationById(id);
    }
    @Override
    public int deleteTrBasRouteOperation(Assist assist){
        return trBasRouteOperationDao.deleteTrBasRouteOperation(assist);
    }
    @Override
    public int updateTrBasRouteOperationById(TrBasRouteOperation enti){
        return trBasRouteOperationDao.updateTrBasRouteOperationById(enti);
    }
    @Override
    public int updateTrBasRouteOperation(TrBasRouteOperation value, Assist assist){
        return trBasRouteOperationDao.updateTrBasRouteOperation(value,assist);
    }
    @Override
    public int updateNonEmptyTrBasRouteOperationById(TrBasRouteOperation enti){
        return trBasRouteOperationDao.updateNonEmptyTrBasRouteOperationById(enti);
    }
    @Override
    public int updateNonEmptyTrBasRouteOperation(TrBasRouteOperation value, Assist assist){
        return trBasRouteOperationDao.updateNonEmptyTrBasRouteOperation(value,assist);
    }

    public TrBasRouteOperationDao getTrBasRouteOperationDao() {
        return this.trBasRouteOperationDao;
    }

    public void setTrBasRouteOperationDao(TrBasRouteOperationDao trBasRouteOperationDao) {
        this.trBasRouteOperationDao = trBasRouteOperationDao;
    }
	@Override
	public ResultBean save(TrBasRouteOperation tro) {
		ResultBean resultBean = new ResultBean(true);
		Assist assist = new Assist();
		assist.setRequires(Assist.andEq("route_id", tro.getRouteId()));
		assist.setRequires(Assist.andEq("operation_id", tro.getOperationId()));
		List<TrBasRouteOperation> selectTrBasRouteOperation = trBasRouteOperationDao.selectTrBasRouteOperation(assist);
		if (selectTrBasRouteOperation.size() > 0) {
			resultBean.setSuccess(false);
			resultBean.setMessage("工序"+tro.getOperation()+"已存在！");
			return resultBean;
		}
		TmBasRoute route = tmBasRouteService.selectTmBasRouteById(tro.getRouteId());
		tro.setRoute(route.getRouteName());
		tro.setCreateTime(new Date());
		tro.setCreateUser(SpringWebUtils.getRequestUser());
		tro.setCompanyCode(SpringWebUtils.getRequestCompany());
		trBasRouteOperationDao.insertTrBasRouteOperation(tro);
		return resultBean;
	}

}